package sql2005;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class JDBC {

	public static void main(String[] args) {
		// load driver\
		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

			// tao ket noi
			Connection conn = DriverManager
					.getConnection("jdbc:sqlserver://127.0.0.1:1433;databaseName=test;user=sa;password=sa");

			String sql = "INSERT INTO SINHVIEN VALUES(?, ?, ?)";

			PreparedStatement pre = conn.prepareStatement(sql);
			pre.setInt(1, 988);
			pre.setString(2, "ten 988");
			pre.setDate(3, new java.sql.Date(new java.util.Date().getTime()));

			int rowUpdate = pre.executeUpdate();

			System.out.println("so dong thay doi = " + rowUpdate);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
